// .txt

beginzonescript;

variables;

short crime_tolerance = 5;
short last_abil;
short i;
short thahd_ctr = 0;
short vat_ctr = 0;
short mehken_made = 0;

body;

beginstate INIT_STATE;
	set_level(8,1);
	set_level(9,1);
	set_level(10,1);
	set_level(11,1);
	
	if ((char_ok(9) == FALSE) && (char_ok(10) == FALSE)) {
		spawn_creature(22);
		spawn_creature(23);
		}
		
	set_name(50,"Controller Mind");
	set_name(51,"Stocky Thahd");
	set_name(52,"Enslaved Servile");
	set_name(53,"Enslaved Servile");
	set_name(54,"Enslaved Servile");

	set_name(55,"Rogue Servile");
	set_name(56,"Rogue Servile");
	set_name(57,"Rogue Servile");
	change_max_health(55,100);
	change_max_health(56,100);
	change_max_health(57,100);
	set_level(55,3);
	set_level(56,3);
	set_level(57,3);
	set_aggression(55,8);
	set_aggression(56,8);
	set_aggression(57,8);
	
	set_name(58,"Agent Alurha");
	set_boss_level(58,2);
	set_name(62,"Sage Fefer");
	set_boss_level(62,1);
	set_name(63,"Shaper Bruel");
	set_boss_level(63,2);
	set_name(67,"Guardian Manola");
	set_boss_level(67,2);
	set_name(71,"Tinker Thule");

	set_name(72,"Gevik");
	set_courage(72,0);
	if (gf(2,12) > 0)
		erase_char(72);
	sf(3,12,0);

//	add_range_to_group(first,last,whichg);

	if (gf(100,11) > 0) {
		print_str_color("Word of your infamy has gotten here before you. You are forever marked",3);
		print_str_color("  as a foe of the Shapers.",3);
		sf(1,6,1);
		}
		
	if (get_sdf(1,6) > 0) {
		make_zone_hostile();
		}
		else {
			print_str_color("This is a friendly fortress. You are able to rest.",2);
			revive_party();
			}	

	last_abil = get_current_tick();
	
	set_crime_tolerance(crime_tolerance);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((char_in_party(47) < 0) && (gf(1,6) == 0) && (gf(2,1) == 1) && (gf(3,22) != 1) && (gf(7,7) == 0) && (mehken_made == 0)) {
		mehken_made = 1;
		spawn_creature(65);
		set_name(73,"Mehken");
		set_level(73,3);
		change_max_health(73,50);
		}

	// clear zone?
	//if ((zone_clear(ME) == FALSE) && (get_flag(,) > 0)) {
		//print_str_color("",2);
		//clear_zone(ME);	
		//}
	
	if ((gf(1,6) == 0) && (char_ok(50)) && (get_attitude(50) >= 10)) {
		make_zone_hostile();
		set_flag(1,6,1);
		}
		
	if ((get_crime_level() >= crime_tolerance) && (get_sdf(1,6) == 0)) {
		make_zone_hostile();
		set_flag(1,6,1);
		}
	if ((gf(1,6) > 0) && (gf(2,1) < 2)) 
		begin_talk_mode(290);

	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(50,"Calm.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(50,"Pause.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(50,"Seek.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(50,"Wait for command.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(50,"Command incoming.");
	if ((gf(2,1) < 2) && (gf(3,19) == 0))
		{
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(38,"We will test you.");
		if ((get_ran(1,0,100) < 10) && (gf(7,7) == 0)) 
			give_char_text_bubble(38,"Your first task awaits.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(38,"Come, minion.");
		}
	if ((gf(2,1) >= 2) && (gf(3,19) == 0))
		{
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(38,"Your abilities develop.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(38,"More work awaits.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(38,"You would speak, minion?");
		}
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(58,"Ah. Rawal's creature.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(58,"You are no Shaper.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(58,"What of our laws?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(58,"Signs of Trakovites?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(62,"Stay!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(62,"Stop!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(62,"Poke. Poke.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(62,"Need another sample.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(51,"Rrrrr.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(51,"Grahrr!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(63,"Happy to help you.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(63,"I'm eager to serve.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(63,"Whatever Rawal commands.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(71,"Tap. Tap.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(71,"Tik! Tik! Tik!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(71,"Am done.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(67,"Hah!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(67,"Guard!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(67,"Parry!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(67,"Slash!");

	if (  
	  ((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
		last_abil = get_current_tick();
		if ((gf(2,6) > 0) && (thahd_ctr <= 3)) {
			if (char_ok(8 + thahd_ctr)) {
				print_str_color("A guard thahd has gone rogue!",2);
				set_attitude(8 + thahd_ctr,10);
				}
			thahd_ctr = thahd_ctr + 1;
			}
		
		if (gf(3,29) == 1) {
			vat_ctr = vat_ctr + 1;
			if (vat_ctr == 1) {
				spawn_creature(4);
				place_particle_num(12,10,7,10);
				give_char_text_bubble(12,"Bloop!");
				spawn_creature(5);
				place_particle_num(13,10,7,10);
				give_char_text_bubble(13,"Bloop!");
				run_sparkles_on_object(98,2,4,1);
				
				play_sound(148);
				print_str_color("The cauldron spits out two huge globules of essence.",2);
				}
			if (vat_ctr == 3) {
				spawn_creature(6);
				place_particle_num(14,10,7,10);
				give_char_text_bubble(14,"Bloop!");
				spawn_creature(7);
				place_particle_num(15,10,7,10);
				give_char_text_bubble(15,"Bloop!");

				run_sparkles_on_object(98,2,4,1);
				
				play_sound(148);
				print_str_color("The cauldron spits out two huge globules of essence.",2);
				}
			if ((vat_ctr == 4) && (party_dist_to_nav(0) <= 10)) {
				play_sound(148);
				print_str_color("The cauldron sprays out a cloud of vile gas.",2);
				run_sparkles_on_object(98,2,4,1);
				i = 0;
				while (i < 8) {
					if (char_ok(i)) {
						if (dist_to_nav_point(i,0) <= 8)
							set_char_status(i,0,-8);
						}
					i = i + 1;
					}
				}
			if (vat_ctr == 5) {
				spawn_creature(8);
				place_particle_num(16,10,7,10);
				give_char_text_bubble(16,"Bloop!");
				spawn_creature(9);
				place_particle_num(17,10,7,10);
				give_char_text_bubble(17,"Bloop!");
				spawn_creature(10);
				place_particle_num(18,10,7,10);
				give_char_text_bubble(18,"Bloop!");

				run_sparkles_on_object(98,2,4,1);
				
				play_sound(148);
				print_str_color("The cauldron spits out three huge globules of essence.",2);
				}
			if ((vat_ctr == 6) && (party_dist_to_nav(0) <= 10)) {
				play_sound(148);
				print_str_color("The cauldron sprays out a cloud of vile gas.",2);
				run_sparkles_on_object(98,2,4,1);
				i = 0;
				while (i < 8) {
					if (char_ok(i)) {
						if (dist_to_nav_point(i,0) <= 8)
							set_char_status(i,8,-8);
						}
					i = i + 1;
					}
				}
			if (vat_ctr == 7) {
				spawn_creature(8);
				place_particle_num(16,10,7,10);
				give_char_text_bubble(16,"Bloop!");
				spawn_creature(9);
				place_particle_num(17,10,7,10);
				give_char_text_bubble(17,"Bloop!");
				spawn_creature(10);
				place_particle_num(18,10,7,10);
				give_char_text_bubble(18,"Bloop!");

				run_sparkles_on_object(98,2,4,1);
				
				play_sound(148);
				print_str_color("The cauldron spits out three huge globules of essence.",2);
				}
			if (vat_ctr == 8) {
				spawn_creature(11);
				place_particle_num(19,10,7,10);
				give_char_text_bubble(19,"BLOOP!");
				change_max_health(19,50);
				set_boss_level(19,1);
				set_name(19,"Huge Fyora");
				run_sparkles_on_object(98,2,4,1);
				
				play_sound(148);
				print_str_color("The cauldron spits out an enormous globule of essence.",2);
				print_str_color("  It is finally empty.",2);
				kill_object(98,0);
				sf(3,29,2);
				}

			}
		}
break;

beginstate 10;
	set_terrain_string_range("The sign says - Foundry Core West.",3);
break;

beginstate 11;
	set_terrain_string_range("The sign says - Private Quarters.",3);
break;

beginstate 12;
	set_terrain_string_range("The sign says - WARNING! Guarded Area! Creation Attacks On Sight!",3);
break;

beginstate 13;
	set_terrain_string_range("The sign says - Shaping Laboratory.",3);
break;

beginstate 14;
	set_terrain_string_range("The sign says - Creation Analysis.",3);
break;

beginstate 15;
	set_terrain_string_range("The sign says - Crystal Workshop.",3);
break;
//	print_str("");
//	set_terrain_string_range(".",3);
//	
